﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tasks.Common.Entitys;
using Tasks.Common;
using Tasks.API;

namespace Tasks.Core
{
    public class SMSHelper
    {
        #region "短信模板"

        /// <summary>
        /// 短信模板支付线路成功
        /// </summary>
        public static string 短信模板支付线路成功(int ownerID)
        {

            return Config.GetConfigForDict(DictConfig.SITE_GLOBAL_SET, "短信模板-支付线路成功", ownerID);

        }

        /// <summary>
        /// 短信模板套票IC卡初始成功
        /// </summary>
        /// <param name="ownerID"></param>
        /// <returns></returns>
        public static string 短信模板套票IC卡激活成功(int ownerID)
        {
            return Config.GetConfigForDict(DictConfig.SITE_GLOBAL_SET, "短信模板-套票IC卡激活成功", ownerID);
        }

        /// <summary>
        /// 短信模板套票门票成功消费
        /// </summary>
        /// <param name="ownerID"></param>
        /// <returns></returns>
        public static string 短信模板套票门票成功消费(int ownerID)
        {
            return Config.GetConfigForDict(DictConfig.SITE_GLOBAL_SET, "短信模板-套票门票成功消费", ownerID);
        }

        /// <summary>
        /// 短信模板套票酒店成功消费
        /// </summary>
        /// <param name="ownerID"></param>
        /// <returns></returns>
        public static string 短信模板套票酒店成功消费(int ownerID)
        {
            return Config.GetConfigForDict(DictConfig.SITE_GLOBAL_SET, "短信模板-套票酒店成功消费", ownerID);
        }

        /// <summary>
        /// 短信模板套票酒店成功预订
        /// </summary>
        /// <param name="ownerID"></param>
        /// <returns></returns>
        public static string 短信模板套票酒店成功预订(int ownerID)
        {
            return Config.GetConfigForDict(DictConfig.SITE_GLOBAL_SET, "短信模板-套票酒店成功预订", ownerID);
        }

        /// <summary>
        /// 短信模板套票酒店预订失败
        /// </summary>
        /// <param name="ownerID"></param>
        /// <returns></returns>
        public static string 短信模板套票酒店预订失败(int ownerID)
        {
            return Config.GetConfigForDict(DictConfig.SITE_GLOBAL_SET, "短信模板-套票酒店预订失败", ownerID);
        }

        /// <summary>
        /// 短信模板预订线路成功
        /// </summary>
        public static string 短信模板预订线路成功(int ownerID)
        {
            return Config.GetConfigForDict(DictConfig.SITE_GLOBAL_SET, "短信模板-预订线路成功", ownerID);
        }
        public static string 短信模板支付套票成功(int ownerID)
        {
            return Config.GetConfigForDict(DictConfig.SITE_GLOBAL_SET, "短信模板-支付套票成功", ownerID);
        }
        /// <summary>
        /// 短信模板支付门票成功
        /// </summary>
        public static string 短信模板支付门票成功(int ownerID)
        {

            return Config.GetConfigForDict(DictConfig.SITE_GLOBAL_SET, "短信模板-支付门票成功", ownerID);

        }
        /// <summary>
        /// 短信模板预订门票成功
        /// </summary>
        public static string 短信模板预订门票成功(int ownerID)
        {

            return Config.GetConfigForDict(DictConfig.SITE_GLOBAL_SET, "短信模板-预订门票成功", ownerID);

        }

        #endregion

        /// <summary>
        /// IC卡激活短信格式化
        /// </summary>
        /// <param name="template"></param>
        /// <param name="clientName"></param>
        /// <param name="smartTicketNo"></param>
        /// <param name="ticketGroupName"></param>
        /// <returns></returns>
        public static string FormatActivationSMS(string template, string clientName, string smartTicketNo, string ticketGroupName)
        {
            template = template.Replace("{客户姓名}", clientName);
            template = template.Replace("{发生日期}", DateTime.Now.ToString());
            template = template.Replace("{套票名称}", ticketGroupName);
            template = template.Replace("{IC卡号}", smartTicketNo);
            return template;
        }


        /// <summary>
        /// 套票景区消费成功短信格式化
        /// </summary>
        /// <param name="template"></param>
        /// <param name="clientName"></param>
        /// <param name="ticketGroupName"></param>
        /// <param name="sceneryName"></param>
        /// <param name="ticketName"></param>
        /// <returns></returns>
        public static string FormatSceneryOrderSMS(string template, string clientName, string ticketGroupName, string sceneryName, string ticketName)
        {
            template = template.Replace("{客户姓名}", clientName);
            template = template.Replace("{发生日期}", DateTime.Now.ToString());
            template = template.Replace("{套票名称}", ticketGroupName);
            template = template.Replace("{景区名称}", sceneryName);
            template = template.Replace("{门票名称}", ticketName);
            return template;
        }

        /// <summary>
        /// 套票酒店消费格式化短信
        /// </summary>
        /// <param name="template"></param>
        /// <param name="clientName"></param>
        /// <param name="ticketGroupName"></param>
        /// <param name="hotelName"></param>
        /// <returns></returns>
        public static string FormatHotelOrderSMS(string template, string clientName, string ticketGroupName, string hotelName)
        {
            template = template.Replace("{客户姓名}", clientName);
            template = template.Replace("{发生日期}", DateTime.Now.ToString());
            template = template.Replace("{套票名称}", ticketGroupName);
            template = template.Replace("{酒店名称}", hotelName);
            return template;
        }

        /// <summary>
        /// 格式化预订酒店成功短信
        /// </summary>
        /// <param name="template"></param>
        /// <param name="clientName"></param>
        /// <param name="createTime"></param>
        /// <param name="hotlName"></param>
        /// <param name="roomName"></param>
        /// <param name="inTime"></param>
        /// <returns></returns>
        public static string FormatBookingHotelSuccSMS(string template, string clientName, string hotelName, string roomName, string inTime)
        {
            template = template.Replace("{客户姓名}", clientName);
            template = template.Replace("{发生日期}", DateTime.Now.ToString());
            template = template.Replace("{酒店名称}", hotelName);
            template = template.Replace("{房型名称}", roomName);
            template = template.Replace("{入住时间}", inTime);
            return template;
        }

        /// <summary>
        /// 格式化预订酒店失败短信
        /// </summary>
        /// <param name="template"></param>
        /// <param name="clientName"></param>
        /// <param name="hotelName"></param>
        /// <param name="roomName"></param>
        /// <param name="inTime"></param>
        /// <returns></returns>
        public static string FormatBookingHotelFailSMS(string template, string clientName, string hotelName, string remark)
        {
            template = template.Replace("{客户姓名}", clientName);
            template = template.Replace("{发生日期}", DateTime.Now.ToString());
            template = template.Replace("{酒店名称}", hotelName);
            template = template.Replace("{失败原因}", remark);
            return template;
        }

        /// <summary>
        /// 格式化短信
        /// </summary>
        /// <param name="template"></param>
        /// <param name="clientName"></param>
        /// <param name="productName"></param>
        /// <param name="money"></param>
        /// <returns></returns>
        public static string FormatSMS(string template, string clientName, string productName, decimal money)
        {
            template = template.Replace("{预订人}", clientName);
            template = template.Replace("{产品名称}", productName);
            template = template.Replace("{金额}", money.ToString());

            return template;
        }

        /// <summary>
        /// 发送预订线路订单SMS
        /// </summary>
        /// <param name="order">订单信息</param>
        /// <param name="smsType">1 支付成功订单  2 订单预订成功 </param>
        /// <returns></returns>
        public static ExecuteResult SendTourSMS(TourOrder order, int smsType)
        {
            string sms = "";
            switch (smsType)
            {
                case 1:
                    sms = FormatSMS(SMSHelper.短信模板支付线路成功(order.OwnerID), order.ClientName, order.TourName, order.TotalPrice);
                    break;
                case 2:
                    sms = FormatSMS(SMSHelper.短信模板预订线路成功(order.OwnerID), order.ClientName, order.TourName, order.TotalPrice);
                    break;
            }

            bool r = SMSAPI.SendSMS(order.ClientTel, sms); //发送短信
            if (r)
                return new ExecuteResult() { ResultNo = 1, Message = "发送成功" };
            else
                return new ExecuteResult() { ResultNo = -1, Message = "发送失败" };
        }

        /// <summary>
        /// 发送预订线路订单SMS
        /// </summary>
        /// <param name="order">订单信息</param>
        /// <param name="smsType">1 支付成功订单  2 订单预订成功 </param>
        /// <returns></returns>
        public static ExecuteResult SendTicketGroupSMS(TicketGroupOrder order)
        {
            string sms = "";
            sms = FormatSMS(SMSHelper.短信模板支付套票成功(Config.CompanyID), order.BuyerName, order.ProductName, order.Money);
            bool r = SMSAPI.SendSMS(order.RecipientMb, sms); //发送短信
            if (r)
                return new ExecuteResult() { ResultNo = 1, Message = "发送成功" };
            else
                return new ExecuteResult() { ResultNo = -1, Message = "发送失败" };
        }

        /// <summary>
        /// 发送预订门票订单SMS
        /// </summary>
        /// <param name="order">订单信息</param>
        /// <param name="smsType">1 支付成功订单  2 订单预订成功 </param>
        /// <returns></returns>
        public static ExecuteResult SendTicketSMS(SceneryTicketOrder order, int smsType)
        {
            string sms1 = "{0},您好！您预订{1}景区的门票，{2}元支付成功！稍后工作人员将为您出票！爱游网";
            string sms2 = "{0},您好！您预订{1}景区的门票，{2}元已预订成功！提醒您按时到达进去游玩，祝您旅途愉快！爱游网";
            string sms = "";

            switch (smsType)
            {
                case 1:
                    sms = string.Format(sms1, order.ClientName, order.SceneryName, order.TotalPrice);
                    break;
                case 2:
                    sms = string.Format(sms2, order.ClientName, order.SceneryName, order.TotalPrice);
                    break;
            }

            bool r = SMSAPI.SendSMS(order.ClientTel, sms); //发送短信
            if (r)
                return new ExecuteResult() { ResultNo = 1, Message = "发送成功" };
            else
                return new ExecuteResult() { ResultNo = -1, Message = "发送失败" };
        }

    }
}
